<?php

declare(strict_types=1);

namespace App\Amqp\Consumer;

use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use PhpAmqpLib\Message\AMQPMessage;
use App\Amqp\Dealwith\DealWith;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Amqp\Message\Type;
#[Consumer(exchange: 'slots_exchange', routingKey: 'slots_roteking', queue: 'slots_queue', name: "SlotsConsumer", nums: 1, enable: true)]
class SlotsConsumer extends ConsumerMessage
{

    protected Type|string $type = Type::DIRECT; //Type::FANOUT;
    #[Inject]
    private DealWith $DealWith;

    private array $consumerTag = ['slotsLog' => 'SlotsLogDealWith'];

    public function consumeMessage($data, AMQPMessage $message): Result
    {
        $exchange = $this->getExchange();
        $routingKey = $this->getRoutingKey();
        $queue = $this->getQueue();

        // Do something with the exchange, routing key, and queue names
        /*var_dump('Exchange: ' . $exchange);
        var_dump('Routing Key: ' . $routingKey);
        var_dump('Queue: ' . $queue);*/

        $Fun = isset($this->consumerTag[$data['consumer_tag']]) ? $this->consumerTag[$data['consumer_tag']] : '';
        if(!$Fun)return Result::ACK;

        $res = $this->DealWith->$Fun($data);
        if(!$res) return Result::REQUEUE;
        return Result::ACK;
    }
}

